package com.yupi.springbootinit.model.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * 设备信息
 */
@Data
@TableName("device_info")
public class DeviceInfo implements Serializable {
    @TableId(type = IdType.AUTO)
    private Integer id;

    @TableField("device_name")
    private String deviceName;
    /**
     * 设备编码（如：02、05，用于批次编码）
     */
    @TableField("device_code")
    private String deviceCode;

    @TableField("influx_tag_name")
    private String influxTagName;

    @TableField("influx_measurements")
    private String influxMeasurements;

    @TableField("ip_address")
    private String ipAddress;

    @TableField("protocol_type")
    private String protocolType;

    @TableField("mqtt_topic")
    private String mqttTopic;

    @TableField("powder_capacity")
    private Double powderCapacity;

    @TableField("remark")
    private String remark;

    @TableField("create_time")
    private LocalDateTime createTime;

    @TableField("update_time")
    private LocalDateTime updateTime;

    private static final long serialVersionUID = 1L;


    /**
     * 解析 CSV 格式的 influx_measurements，返回 List
     */
    public List<String> getInfluxMeasurementList() {
        if (influxMeasurements == null || influxMeasurements.isBlank()) {
            return Collections.emptyList();
        }
        // 去空格后拆分
        return Arrays.stream(influxMeasurements.split(","))
                .map(String::trim)
                .toList();
    }
}